var sharedData=require("dataMgr");
var helper=require("Helpers");
//处理弹出框脚本，升级角色属性
cc.Class({
    extends: cc.Component,

    properties: {
        addGoldLabel:{
            default:null,
            type:cc.Label
        },
        curScoreLabel:{
            default:null,
            type:cc.Label
        },
        timeLeftLayer:{
            default:null,
            type:cc.Node
        },
        seeVideoBnt:{
            default:null,
            type:cc.Node
        },
        clickPassBnt:{
            default:null,
            type:cc.Node
        }
    },

    startShow:function(game,score){
        this._game=game;
        this._score=score;
        this._gold=parseInt(score/sharedData.games.scoreToGold);
        //开始显示弹框
        this.node.active=true;
        this.curScoreLabel.string=helper.getKNum(this._score);
        this.addGoldLabel.string="+"+helper.getKNum(this._gold);
        this.timeLeftLayer.getComponent("timeleft").startLeft(sharedData.games.vedioPassTime,function(){
            //结束的时候
            this.restartGame();
        }.bind(this));
    },

    restartGame:function(){
        //在这里把值都计算进去
        sharedData.setLastScore(this._score);
        sharedData.addRoleGold(this._gold);

        this.dismissDialog();
        this._game.restartGame(true);
    },

    seeMovie:function(){
        this.dismissDialog();
        //this._game.seeMovie();
        this._game.resumeGame();
    },

     dismissDialog:function(){
        this.node.active=false;
     },

    // LIFE-CYCLE CALLBACKS:
    onLoad:function() {
        this.seeVideoBnt.getComponent("button")._callback=function(){
            //点击看视频，暂时重新恢复游戏
            this.timeLeftLayer.getComponent("timeleft").resetInfo();
            this.seeMovie();
         }.bind(this);
 
         this.clickPassBnt.on(cc.Node.EventType.TOUCH_END, function (e) {
             //直接在这里dismiss掉
             this.timeLeftLayer.getComponent("timeleft").resetInfo();
             this.restartGame();
 
         }.bind(this), this);
    },
});
